import {Link, LinkProps} from 'react-router-dom';
import React from "react";
import {Empower} from "@/components/ant-ext/empower";
import {hasIdentityUrl, HRouteMedata} from "@/config/route/route-func";


export default class HLink extends React.Component<LinkProps & Empower, any> {

    render() {

        const props = this.props;

        if (props.to === "#" || props.to === "" || props.to === undefined) {
            return <>{props.children}</>
        }
        // @ts-ignore
        const element = HRouteMedata.mapping[this.props.to];
        if (element) {
            if (!element.identity || hasIdentityUrl(this.props.to)) {
                return <Link to={props.to}>
                    {this.props.children}
                </Link>;
            }
        }
        return <Link to={`/503?path=${props.to}`}> {props.children}</Link>;
    }
}

